package com.company.steamAPI.demo1;

import com.company.steamAPI.MainApp;
import com.company.steamAPI.Trader;
import com.company.steamAPI.Transaction;
import org.junit.jupiter.api.Test;


import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName Demo1
 * @Description TODO
 * @Author 11
 * @Date 2021/7/12 15:15
 * @Version 1.0
 */
public class Demo1 {
    private static MainApp mainApp = new MainApp();
    private List<Transaction> transactionList = mainApp.getTransactionList();
    @Test
    public  void test1() {

        List<Transaction> list = transactionList.stream().
                filter(f -> f.getYear().equals(2011)).
                sorted((e1, e2) -> e2.getValue() - e1.getValue()).
                collect(Collectors.toList());
        System.out.println(list.toString());


    }



    @Test
    public void test2(){
        System.out.println(transactionList.stream()
                .map(Transaction::getTrader)
                .map(Trader::getCity)
                .distinct()
                .collect(Collectors.toList()));


    }



    @Test
    public void test3(){
        System.out.println(transactionList.stream()
                .map(Transaction::getTrader)
                .filter(t ->t.getCity().equals("Cambridge"))
                .sorted((t1,t2)->t1.getName().compareTo(t2.getName()))
                .collect(Collectors.toList())
        );
    }
}
